﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace baseClass.Forms
{
    public partial class projectFind : dataFind 
    {
        private projectEdit myProjectEdit = null;
        public projectFind()
        {
            InitializeComponent();
            this.projectGrid.SetDataSource(myBaseDS.emProject);
            this.myFullMode = false;
        }
        public data.baseDS.emProjectRow mySelectedDataRow = null;
        protected override common.controls.baseDataGridView CreateDataGrid()
        {
            return projectGrid;
        }
        public override bool Find(string code, bool force)
        {
            bool HaveMarker = common.SysLibs.HaveFindMarker(ref code);
            code = code.Trim();
            this.mySelectedDataRow = null;

            //Detect FORCE mode : when finding code contains charcter ? 
            if (common.StringLibs.IsNullOrEmpty(code) || HaveMarker) force = true;

            if (force == false)
            {
                DataAccess.DataLibs.OptionValues options = new DataAccess.DataLibs.OptionValues();
                options.Code = code;
                myBaseDS.emProject.Clear();
                DataAccess.DataLibs.LoadData(myBaseDS.emProject, options);
                if (myBaseDS.geStatement.Count >= 1)
                {
                    this.mySelectedDataRow = myBaseDS.emProject[0];
                    return true;
                }
            }
            this.myFullMode = (myBaseDS.emProject.Count > 0);
            this.Visible = false;
            this.ShowDialog();
            return (this.mySelectedDataRow != null);
        }
        protected override void DoSelect()
        {
            if (projectsSource.Current == null) return;
            this.mySelectedDataRow = (data.baseDS.emProjectRow)((DataRowView)projectsSource.Current).Row;
            this.Close();
        }
        public override bool LoadData()
        {
            this.mySelectedDataRow = null;
            this.myBaseDS.emProject.Clear();
            DataAccess.DataLibs.LoadData(this.myBaseDS.emProject, projectCriteria.GetOptions());
            ShowReccount(projectsSource.Count);
            return true;
        }
        
        private void newBtn_Click(object sender, EventArgs e)
        {
            if (myProjectEdit == null || myProjectEdit.IsDisposed) myProjectEdit = new projectEdit();
            myProjectEdit.ShowProject(null);
        }

    }
}
